home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Packages / smarterSource.tcl < prev    next >
Encoding:
Text File  |  1997-10-08  |  4.3 KB  |  108 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*- (install)
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "smarterSource.tcl"
  6.  #                                    created: 18/10/95 {6:00:07 pm} 
  7.  #                                last update: 8/10/97 {8:32:42 pm} 
  8.  #  
  9.  #  WARNING:  This file was recently fixed to implement the proper
  10.  #  behaviour of the 'source' command -- to source into the current
  11.  #  scope.  Previously this procedure would always source into the
  12.  #  global scope.  Scripts which relied on the old behaviour must be
  13.  #  fixed...  
  14.  #  
  15.  #  Files in PREFS are passed through unchanged.  Simplified proc.
  16.  #  Interacts ok with package rebuilding.
  17.  # ##################################################################
  18.  ##
  19.  
  20. ## 
  21.  # VMD May'95-Oct'97: <darley@fas.harvard.edu>
  22.  # 
  23.  # Changed default directory to    the    the    alpha preferences directory.
  24.  # Changed extension to    '+'    rather than    'bullet' (option-8)    because
  25.  # of ascii    transmission problems -    lots of    people have    a non-working
  26.  # version of this file.
  27.  # 
  28.  # Passes through 'tclIndex(x)' and 'prefs.tcl' unchanged.
  29.  # 
  30.  # Renamed this    file to    'smarterSource.tcl', originally    just to    differentiate
  31.  # it from the old crippled    versions.
  32.  # 
  33.  # IMPORTANT: Fixed    the    script so that it works    with path names    containing
  34.  # spaces.  Changed all 'uplevel #0' to 'uplevel 1'.  
  35.  # 
  36.  ##
  37.  
  38. #############################################################################
  39. # BASED UPON 'smartSource.tcl':
  40. #
  41. # Copyright 1994, Robert Browning (osiris@cs.utexas.edu): This code is made 
  42. # freely available to anyone who can find a use for it. Consider it part of my
  43. # thanks to all those who have contributed to the freeware and shareware base.
  44. # (Especially Pete Keheler, without which this code would be pretty useless).
  45. # === Modifications by Vince, May 1995 ===
  46. #############################################################################
  47.  
  48. alpha::extension smarterSource 0.1 {
  49. newPref folder tclExtensionsFolder "$PREFS"
  50. if {![string length [info commands dumbSource]]} {
  51.     rename source dumbSource
  52. }
  53. ;proc source {filename} {
  54.     global tclExtensionsFolder PREFS
  55.     set justName [file tail "$filename"]
  56.     # we don't want to over-ride these files
  57.     if { [lsearch -exact {tclIndex tclIndexx prefs.tcl} $justName] != -1 \
  58.       || [string match "${PREFS}:*${justName}" $filename] } {
  59.         return [uplevel 1 [list dumbSource $filename]] 
  60.     }
  61.     
  62.     set overrideFile "${tclExtensionsFolder}:${justName}"
  63.     if {[file exists $overrideFile]} {
  64.         set returnVal [uplevel 1 [list dumbSource $overrideFile]]
  65.     } else {
  66.         set returnVal [uplevel 1 [list dumbSource $filename]]
  67.     }
  68.         
  69.     set extensionFiles [glob -nocomplain \
  70.       "[file root $overrideFile]+*[file extension ${justName}]"]
  71.     
  72.     foreach extensionFile $extensionFiles {
  73.         set returnVal [uplevel 1 [list dumbSource $extensionFile]]
  74.     }
  75.     return "$returnVal" 
  76. }
  77. # end package block
  78. } help {
  79.     This package implements a replacement source command. It is intended to help
  80.     make the process of augmenting Alpha's code base with your own changes less
  81.     awkward, especially in the face of program updates. It also makes it so
  82.     that you no longer have to source files containing procedures that you want
  83.     to override in your UserStartup file.
  84.     
  85.     Basically, you designate a directory to contain your files. Then
  86.     any time Alpha is instructed to source a file named filename.tcl, it will
  87.     first look in the directory you have designated, and if there is a file of
  88.     the identical name there (i.e. filename.extension) it will source that file
  89.     instead of the original one specified. If there are any files named
  90.     filename+*.extension it will source those in the order returned by glob after
  91.     either the original filename.extension or the replacement has been sourced.
  92.     
  93.     For example, if your TclExtensions directory contains files named
  94.     latex+1.tcl and latex+2.tcl, then whenever you try to open a latex file
  95.     Alpha will first source the standard latex.tcl file, then latex+1.tcl, then
  96.     latex+2.tcl. If there was also a file named latex.tcl in the TclExtensions
  97.     directory then that file would be sourced in place of the standard
  98.     latex.tcl, then latex+1.tcl, then latex+2.tcl.
  99.     
  100.     You may just want to use filename+.extension for a single extension file.
  101.     
  102.     Note that latex+10.tcl would be sourced _before_ latex+9.tcl, so you
  103.     may wish to use latex+01.tcl ... latex+99.tcl to make things clearer.
  104. }
  105.  
  106.